<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions 
 * @package    Communityad
 * @copyright  Copyright 2009-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: Pagesettings.php  2011-02-16 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Communityad_Model_DbTable_Pagesettings extends Engine_Db_Table {

  protected $_name = 'communityad_pagesettings';
  protected $_rowClass = 'Communityad_Model_Pagesetting';

  // Function: Return the widgets ID which are displayed on page.
  public function displayPageWidgets($pageId) {
    $pagesettingTableName = $this->info('name');
    // Queary: Check that entry are already in data base or not.
    $selectContainer = $this->select()
                    ->from($pagesettingTableName, array('ad_widget_id'));
    if ($pageId != 'none') {
      $selectContainer->where('page_id = ?', $pageId);
    }
    $fetchPagesettings = $selectContainer->query()->fetchAll();
    if (!empty($fetchPagesettings)) {
      foreach ($fetchPagesettings as $widgetsid) {
        $fetchWidgetsId[] = $widgetsid['ad_widget_id'];
      }
      $fetchWidgetsId = array_unique($fetchWidgetsId);
      return $fetchWidgetsId;
    } else {
      return 0;
    }
  }

  // Function: Return the row information.
  public function adwidgetValue($pageId, $adWidgetId) {
    $pagesettingTableName = $this->info('name');
    // Queary: Check that entry are already in data base or not.
    $selectContainer = $this->select()
                    ->from($pagesettingTableName, array('value', 'widget_width', 'widget_height', 'ad_block_title'))
                    ->where('ad_widget_id = ?', $adWidgetId)
                    ->limit(1);
    if ($pageId != 'none') {
      $selectContainer->where('page_id = ?', $pageId);
    }
    $fetchPagesettings = $selectContainer->query()->fetchAll();
    if (!empty($fetchPagesettings)) {
      return $fetchPagesettings[0];
    } else {
      return 0;
    }
  }

  public function widgetCode($adWidgetId, $div) {
    $widgetName = null;
    switch ($adWidgetId) {
      case 21:
        $widgetName = 'communityad.fullwidth-none';
        $className = 'layout_middle';
        break;
      case 22:
        $widgetName = 'communityad.middle-none';
        $className = 'layout_middle';
        break;
      case 23:
        $widgetName = 'communityad.left-none';
        $className = 'layout_left';
        break;
      case 24:
        $widgetName = 'communityad.right-none';
        $className = 'layout_right';
        break;
      case 25:
        $widgetName = 'communityad.extended-none';
        $className = 'layout_middle';
        break;
      case 26:
        $widgetName = 'communityad.featured-fullwidth-none';
        $className = 'layout_middle';
        break;
      case 27:
        $widgetName = 'communityad.featured-middle-none';
        $className = 'layout_middle';
        break;
      case 28:
        $widgetName = 'communityad.featured-left-none';
        $className = 'layout_left';
        break;
      case 29:
        $widgetName = 'communityad.featured-right-none';
        $className = 'layout_right';
        break;
      case 44:
        $widgetName = 'communityad.featured-extended-none';
        $className = 'layout_middle';
        break;
      case 45:
        $widgetName = 'communityad.sponsored-fullwidth-none';
        $className = 'layout_middle';
        break;
      case 46:
        $widgetName = 'communityad.sponsored-middle-none';
        $className = 'layout_middle';
        break;
      case 47:
        $widgetName = 'communityad.sponsored-left-none';
        $className = 'layout_left';
        break;
      case 48:
        $widgetName = 'communityad.sponsored-right-none';
        $className = 'layout_right';
        break;
      case 49:
        $widgetName = 'communityad.sponsored-extended-none';
        $className = 'layout_middle';
        break;
      default:
        return 0;
        break;
    }
    
    if (!empty($div)) {
      return '&lt;div class="' . $className . '"&gt;&lt;?php echo $this->content()->renderWidget("' . $widgetName . '"); ?>&lt;/div&gt;';
    } else {
      return '&lt;?php echo $this->content()->renderWidget("' . $widgetName . '"); ?&gt;';
    }
  }

  public function adwidgetInfo($widgetId) {
    $view = Zend_Registry::isRegistered('Zend_View') ? Zend_Registry::get('Zend_View') : null;
    $widgetInfo = array();
    switch ($widgetId) {
      case 1: // Left 1
        $widgetInfo['name'] = 'communityad.left-1-ads';
        $widgetInfo['position'] = 'left';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Left Column Ads - Widget 1');
        break;

      case 2: // Left 2
        $widgetInfo['name'] = 'communityad.left-2-ads';
        $widgetInfo['position'] = 'left';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Left Column Ads - Widget 2');
        break;

      case 3: // Right 1
        $widgetInfo['name'] = 'communityad.right-ads';
        $widgetInfo['position'] = 'right';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Right Column Ads - Widget 1');
        break;

      case 4: // Right 2
        $widgetInfo['name'] = 'communityad.right-2-ads';
        $widgetInfo['position'] = 'left';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Right Column Ads - Widget 2');
        break;

      case 5: // Middle 1
        $widgetInfo['name'] = 'communityad.middle-1-ads';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Middle Column Ads - Widget 1');
        break;

      case 6: // Middle 2
        $widgetInfo['name'] = 'communityad.middle-2-ads';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Middle Column Ads - Widget 2');
        break;

      case 7: // Middle: Full Width 1
        $widgetInfo['name'] = 'communityad.fullwidth-1-ads';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Full Width Ads - Widget 1');
        break;

      case 8: // Middle: Full Width 2
        $widgetInfo['name'] = 'communityad.fullwidth-2-ads';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Full Width Ads - Widget 2');
        break;

      case 15: // Top: Full width 1
        $widgetInfo['name'] = 'communityad.fullwidth-1-ads';
        $widgetInfo['position'] = 'top';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Full Width Ads - Widget 1');
        break;

      case 16: // Top: Full width 2
        $widgetInfo['name'] = 'communityad.fullwidth-2-ads';
        $widgetInfo['position'] = 'top';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Full Width Ads - Widget 2');
        break;

      case 17:  // Bottom: Full width 2
        $widgetInfo['name'] = 'communityad.fullwidth-1-ads';
        $widgetInfo['position'] = 'bottom';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Full Width Ads - Widget 1');
        break;

      case 18:  // Bottom: Full width 2
        $widgetInfo['name'] = 'communityad.fullwidth-2-ads';
        $widgetInfo['position'] = 'bottom';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Full Width Ads - Widget 2');
        break;

      case 9: // Extended 1
        $widgetInfo['name'] = 'communityad.extended-1-ads';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Extended Right / Left Ads - Widget 1');
        break;

      case 10: // Extended 2
        $widgetInfo['name'] = 'communityad.extended-2-ads';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = null;
        $widgetInfo['placement'] = $view->translate('Extended Right / Left Ads - Widget 2');
        break;

      // static wigdets
      case 21:
        $widgetInfo['name'] = 'communityad.fullwidth-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Full Width Ads');
        break;

      case 22:
        $widgetInfo['name'] = 'communityad.middle-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Middle Column Ads');
        break;

      case 23:
        $widgetInfo['name'] = 'communityad.left-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Left Column Ads');
        break;

      case 24:
        $widgetInfo['name'] = 'communityad.right-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Right Column Ads');
        break;

      case 25:
        $widgetInfo['name'] = 'communityad.extended-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Extended Right / Left Ads');
        break;

      // Start Static'Featured widgets'.
      case 26:
        $widgetInfo['name'] = 'communityad.featured-fullwidth-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Featured Full Width Ads');
        break;

      case 27:
        $widgetInfo['name'] = 'communityad.featured-middle-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Featured Middle Column Ads');
        break;

      case 28:
        $widgetInfo['name'] = 'communityad.featured-left-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Featured Left Column Ads');
        break;

      case 29:
        $widgetInfo['name'] = 'communityad.featured-right-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Featured Right Column Ads');
        break;

      case 44:
        $widgetInfo['name'] = 'communityad.featured-extended-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Featured Extended Right / Left Ads');
        break;

      // Start Static'Sponsored widgets'.
      case 45:
        $widgetInfo['name'] = 'communityad.sponsored-fullwidth-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Sponsored Full Width Ads');
        break;

      case 46:
        $widgetInfo['name'] = 'communityad.sponsored-middle-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Sponsored Middle Column Ads');
        break;

      case 47:
        $widgetInfo['name'] = 'communityad.sponsored-left-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Sponsored Left Column Ads');
        break;

      case 48:
        $widgetInfo['name'] = 'communityad.sponsored-right-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Sponsored Right Column Ads');
        break;

      case 49:
        $widgetInfo['name'] = 'communityad.sponsored-extended-none';
        $widgetInfo['position'] = 'static';
        $widgetInfo['title'] = 0;
        $widgetInfo['placement'] = $view->translate('Non-Widgetized Page: Sponsored Extended Right / Left Ads');
        break;


      // Start 'sponserd widgets'.
      case 30: // Middle: Sponsored widgets.
        $widgetInfo['name'] = 'communityad.sponsored-fullwidth-ad';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Full Width Sponsored Ads Widget');
        break;

      case 31:  // Bottom: Sponserd widgets.
        $widgetInfo['name'] = 'communityad.sponsored-fullwidth-ad';
        $widgetInfo['position'] = 'bottom';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Full Width Sponsored Ads Widget');
        break;

      case 32: // Top: Sponsored widgets.
        $widgetInfo['name'] = 'communityad.sponsored-fullwidth-ad';
        $widgetInfo['position'] = 'top';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Full Width Sponsored Ads Widget');
        break;

      case 33: // Left: Sponsored widgets.
        $widgetInfo['name'] = 'communityad.sponsored-left-ad';
        $widgetInfo['position'] = 'left';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Left Sponsored Ads Widget');
        break;

      case 34: // Middle: Sponserd widgets.
        $widgetInfo['name'] = 'communityad.sponserd-middle-ad';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Middle Sponsored Ads Widget');
        break;

      case 35: // Right: Sponserd Widgets.
        $widgetInfo['name'] = 'communityad.sponserd-right-ad';
        $widgetInfo['position'] = 'right';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Right Sponsored Ads Widget');
        break;

      case 36: // Extended: Sponserd Widgets.
        $widgetInfo['name'] = 'communityad.sponserd-extended-ad';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Extended Right / Left Sponsored Ads Widget');
        break;

      // Start 'Featured widgets'.
      case 37: // Middle: Featured widgets.
        $widgetInfo['name'] = 'communityad.featured-fullwidth-ad';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Full Width Featured Ads Widget');
        break;

      case 38:  // Bottom: Featured widgets.
        $widgetInfo['name'] = 'communityad.featured-fullwidth-ad';
        $widgetInfo['position'] = 'bottom';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Full Width Featured Ads Widget');
        break;

      case 39: // Top: Featured widgets.
        $widgetInfo['name'] = 'communityad.featured-fullwidth-ad';
        $widgetInfo['position'] = 'top';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Full Width Featured Ads Widget');
        break;

      case 40: // Left: Featured widgets.
        $widgetInfo['name'] = 'communityad.featured-left-ad';
        $widgetInfo['position'] = 'left';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Left Featured Ads Widget');
        break;

      case 41: // Middle: Featured widgets.
        $widgetInfo['name'] = 'communityad.featured-middle-ad';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Middle Featured Ads Widget');
        break;

      case 42: // Right: Featured Widgets.
        $widgetInfo['name'] = 'communityad.featured-right-ad';
        $widgetInfo['position'] = 'right';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Right Featured Ads Widget');
        break;

      case 43: // Extended: Featured Widgets.
        $widgetInfo['name'] = 'communityad.featured-extended-ad';
        $widgetInfo['position'] = 'middle';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Extended Right / Left Featured Ads Widget');
        break;

      case 50: // Extended: Featured Widgets.
        $widgetInfo['name'] = 'communityad.footer-ads';
        $widgetInfo['position'] = 'footer';
        $widgetInfo['title'] = '';
        $widgetInfo['placement'] = $view->translate('Footer Ads Widget');
        break;
    }
    return $widgetInfo;
  }

}